import { TrayIcon } from '@tauri-apps/api/tray';
import { defaultWindowIcon } from '@tauri-apps/api/app';
import { getCurrentWindow  } from '@tauri-apps/api/window'
import { Menu } from '@tauri-apps/api/menu';






(async ()=>{
    let icon = await defaultWindowIcon()
    let menu = await Menu.new({
        items: [
            {
                text: '显示主界面',
                id: 'show',
                action: async () => {
                    await getCurrentWindow().show()
                }
            },
            {
                text: '退出',
                id: 'exit',
                action: async () => {
                    await getCurrentWindow().close()
                }
            }
        ]
    })
    const options = {
        icon,
        menu,
        action: async (event) => {
            switch (event.type){
                case 'Click':
                    if(event.button !== 'Left')return
                    await getCurrentWindow().show()
                    break;
            }
        },
        menuOnLeftClick: false
    }

    TrayIcon.new(options)
})()